import { apiMemberIndex } from '../../api/index'
Page({
  /**
   * 页面的初始数据
   */
  data: {
    mineClass: [
      { img: '../../images/ic_mine_distribution@3x.png', text: '会员中心' },
      { img: '../../images/ic_mine_help@3x.png', text: '我的助力' },
      // { img: '../../images/ic_mine_discount@3x.png', text: '优惠券' },
      { img: '../../images/ic_mine_after@3x.png', text: '我的售后' },
      { img: '../../images/ic_mine_invite@3x.png', text: '邀请好友', name: '领现金' },
      { img: '../../images/ic_mine_adress@3x.png', text: '管理地址' },
      { img: '../../images/ic_mine_strategy@3x.png', text: '多拿攻略' },
      { img: '../../images/ic_mine_FAQ@3x.png', text: '常见问题' }
    ],
    mineClass2: [
      { img: '../../images/ic_mine_feedback@3x.png', text: '意见反馈' },
      { img: '../../images/ic_mine_cooperation@3x.png', text: '商务合作' }
    ],
    userImg: '',
    userName: '',
    myOrder: [
      { img: '../../images/ic_mine_obligation@2x.png', text: '待付款' },
      { img: '../../images/ic_mine_committed@2x.png', text: '待发货' },
      { img: '../../images/ic_mine_receiving@2x.png', text: '待收货' },
      { img: '../../images/ic_mine_realy@3x.png', text: '待接力' }
    ]
  },
  // 我的订单
  myOrder () {
    wx.navigateTo({
      url: '../my-order/my-order'
    })
  },
  // 进入会员中心
  toDisCenter () {
    wx.navigateTo({
      url: '../distribution-center/distribution-center'
    })
  },
  // 进入模块
  goInt (e) {
    switch (e.currentTarget.dataset.text) {
      case '常见问题':
        wx.navigateTo({
          url: '../common-problem/common-problem'
        })
        break
      case '管理地址':
        wx.navigateTo({
          url: '../add-admin/add-admin'
        })
        break
      case '优惠券':
        wx.navigateTo({
          url: '../coupon/coupon'
        })
        break
      case '我的助力':
        wx.navigateTo({
          url: '../my-help-order/my-help-order'
        })
        break
      case '邀请好友':
        wx.navigateTo({
          url: '../red-share/red-share'
        })
        break
      case '客服':
        break
      case '会员中心':
        wx.navigateTo({
          url: '../distribution-center/distribution-center'
        })
        break
      case '多拿攻略':
        wx.switchTab({
          url: '../home/home'
        })
        break
      case '意见反馈':
        wx.navigateTo({
          url: '../feedback/feedback'
        })
        break
      case '商务合作':
        wx.showToast({
          title: '暂未开放',
          icon: 'none'
        })
        break
      case '我的售后':
        wx.navigateTo({
          url: '../after-sale/index'
        })
        break
    }
  },
  // 跳转到订单状态
  toOrder (e) {
    let index = e.currentTarget.dataset.index
    wx.navigateTo({
      url: `../my-order/my-order?index=${index}`
    })
  },
  putForward () {
    wx.navigateTo({
      url: '../application-for/application-for'
    })
  },
  // 如何获取
  getMoney () {
    wx.showToast({
      title: '暂无信息',
      icon: 'none'
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad (options) {
    this.setData({
      nickName: JSON.stringify({ nickName: wx.getStorageSync('nickName'), city: wx.getStorageSync('city') })
    })
  },
  // 获取页面信息
  getUser () {
    apiMemberIndex().then(
      res => {
        wx.setStorageSync('user_name', res.data.user_info.user_name)
        wx.setStorageSync('nick_name', res.data.user_info.nick_name)
        wx.setStorageSync('id_card', res.data.user_info.id_card)
        this.setData({
          userInfo: res.data
        })
      }
    )
  },
  toSettlement () {
    wx.navigateTo({
      url: '../settlement/index'
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow () {
    this.getUser()
  }
})
